import { RoleAttributeType } from "../../../../role/model/RoleEnum";
import { Role } from "../../../../role/Role";
import { EffectDamage } from "../../model/report/EffectDamage";
import { RoleAttribute } from "../utils/RoleAttribute";
import { RoleDamage } from "../utils/RoleDamage";
import { RoleSelector } from "../utils/RoleSelector";
import { SkillCasting } from "./SkillCasting";

/** 普通攻击 */
export class SkillCastingNormal extends SkillCasting {
    onCasting(): void {
        var caster = this.caster;

        var targets: Role[] = RoleSelector.findTargets(caster, this.skill.SkillModel.attackType);
        this.targets = targets;
        this.target = targets[0];

        // 普攻加能量
        if(caster.RoleModel.table.hasPower && this.skill.SkillModel.table.skill_type == 1){
            RoleAttribute.add(caster, RoleAttributeType.power, 50);
        }

        // 技能施放战报（施放动画） 注：通过Skill表的anim_cast字段定义是否需要播放施放动画
        this.casting(this.target);

        this.skill.SkillModel.effectDamage = new EffectDamage();

        // 目标受击战报（受击动画）
        targets.forEach(role => {
            // 目标受击战报（受击动画）
            this.skill.SkillModel.effectDamage.value += RoleDamage.normal(this.isr, role).value;
        });

        // 施放技能减能量
        if(caster.RoleModel.table.hasPower && this.skill.SkillModel.table.skill_type == 2){
            RoleAttribute.cover(caster, RoleAttributeType.power, 0);
        }
    }
}